package com.freshfresh.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.freshfresh.activity.R;



public class PointsDetailAdapter extends BaseAdapter {

	private Context context;
	private List<Map<String, Object>> pointsDetailBeans;
	LayoutInflater inflater;

	public PointsDetailAdapter(Context context,
			List<Map<String, Object>> pointsDetailBeans) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.pointsDetailBeans = pointsDetailBeans;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return pointsDetailBeans.size();
	}
	public void onDateChange(List<Map<String, Object>> apk_list) {
		this.pointsDetailBeans = apk_list;
		this.notifyDataSetChanged();
	}


	@Override
	public Object getItem(int position) {
		return pointsDetailBeans.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Map<String, Object> entity = pointsDetailBeans.get(position);
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.activity_points_detail_item, null);
			viewHolder.tv_time = (TextView) convertView
					.findViewById(R.id.tv_time);
			viewHolder.tv_points_count = (TextView) convertView
					.findViewById(R.id.tv_points_count);
			viewHolder.tv_points_type = (TextView) convertView
					.findViewById(R.id.tv_points_type);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.tv_time.setText(entity.get("points_datetime").toString());
		viewHolder.tv_points_count.setText(entity.get("points").toString());
		viewHolder.tv_points_type.setText(entity.get("points_type").toString());
		return convertView;
	}

	class ViewHolder {

		TextView tv_time, tv_points_count, tv_points_type;
	}

}
